/*
* 组件皮肤管理器，用于提供创建组件的接口
*/
class SkinManager{
    constructor(){

    }
	public static createButton(pr: GYSprite, x: number, y: number, source: string, alias: string = null, imgCls: any = null,label:string=""): Button {
		let s = this;
		if (imgCls == null) imgCls = Button;
		let img: Button = new imgCls;
		if (source) img.texture = Main.instance.getRes(source);
		img.x = x;
		img.y = y;
		img.label = label;
		if (pr) pr.addChild(img);
		return img;
	}
    public static createImage(pr: GYSprite, x: number, y: number, source: string, alias: string = null, imgCls: any = null): GYSprite {
		let s = this;
		if (imgCls == null) imgCls = GYSprite;
		let img: GYSprite = new imgCls;
		if (source) img.texture = Main.instance.getRes(source);
		img.x = x;
		img.y = y;
		if (pr) pr.addChild(img);
		return img;
	}
    /**创建文本
	 * @param pr 父级不填则不添加到舞台
	 * @param toX 坐标x 
	 * @param toY 坐标y
	 * @param text 文本
	 * @param color 颜色
	 * @param size 字号
	 * @param align 水平对齐方式 left right center
	 * @param w 宽度
	 * @param h 高度
	*/
	public static createText(pr: GYSprite, toX: number, toY: number, text: string, color: number = 0xffffff, size: number = 20, align: string = "left", w: number = NaN, h: number = NaN, fontFamily: string = ""): GYText {
		let txt: GYText;
		txt = new GYText;
		txt.text = text;
		txt.color = SkinManager.toColorString(color);
		txt.fontSize = size;
		txt.align = align;
		txt.width = w;
		txt.height = h;
		txt.x = toX;
		txt.y = toY;
		if (pr) pr.addChild(txt);
		return txt;
	}
    public static toColorString(value:number):string {
        if (value < 0)
            value = 0;
        if (value > 16777215)
            value = 16777215;

        let color:string = value.toString(16).toUpperCase();
        while (color.length > 6) {
            color = color.slice(1, color.length);
        }
        while (color.length < 6) {
            color = "0" + color;
        }
        return "#" + color;
    }
}